package com.lhkj.ct.meta.modules.patient.model.dto;

import com.lhkj.ct.meta.modules.patient.model.entity.TblPatient;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import org.hibernate.validator.constraints.ScriptAssert;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 描述：档案导入
 * </p>
 */
@Data
public class ImportPatientDto implements Serializable {

    @NotBlank(message = "请选择单位")
    @ApiModelProperty(value = "单位")
    private String unitId;

    @NotNull(message = "请选择账号规则")
    @Range(min = 1, max = 2, message = "账号规则无效")
    @ApiModelProperty(value = "账号规则", notes = "1.证件号 2.手机号")
    private Integer accountPolicy;

    @NotNull(message = "请选择密码规则")
    @Range(min = 1, max = 2, message = "密码规则无效")
    @ApiModelProperty(value = "密码规则", notes = "1.证件号后六位 2.固定密码")
    private Integer pwdPolicy;

    @ApiModelProperty(value = "固定密码")
    private String pwd;

    @NotEmpty(message = "至少导入一个人员信息")
    @ApiModelProperty(value = "姓名")
    @Valid
    private List<PatientInfo> patientInfos;

    @Data
    @ScriptAssert(lang = "javascript",
            script = "org.apache.commons.lang3.StringUtils.isNotBlank(_this.patName)",
            message = "第${validatedValue.ixh}条数据姓名不能为空",
            groups = {Patient.class})
    @ScriptAssert(lang = "javascript",
            script = "_this.patBirthday != null",
            message = "第${validatedValue.ixh}条数据出生日期不能为空",
            groups = {Patient.class})
    @ScriptAssert(lang = "javascript",
            script = "org.apache.commons.lang3.StringUtils.isNotBlank(_this.patSex)",
            message = "第${validatedValue.ixh}条数据性别不能为空",
            groups = {Patient.class})
    @ScriptAssert(lang = "javascript",
            script = "org.apache.commons.lang3.StringUtils.isNotBlank(_this.patIdentType)",
            message = "第${validatedValue.ixh}条数据证件类型不能为空",
            groups = {Patient.class})
    @ScriptAssert(lang = "javascript",
            script = "org.apache.commons.lang3.StringUtils.isNotBlank(_this.patIdentNo)",
            message = "第${validatedValue.ixh}条数据证件号码不能为空",
            groups = {Patient.class})
    @ScriptAssert(lang = "javascript",
            script = "org.apache.commons.lang3.StringUtils.isNotBlank(_this.patMobile) && com.lhkj.ct.base.utils.ValidatedUtils.isPhone(_this.patMobile)",
            message = "第${validatedValue.ixh}条数据手机号不合法",
            groups = {Phone.class})
    public static class PatientInfo {

        @NotNull(message = "序号不能为null")
        @ApiModelProperty(value = "序号")
        private Long ixh;

        @ApiModelProperty(value = "姓名")
        private String patName;

        @ApiModelProperty(value = "性别")
        private String patSex;

        @ApiModelProperty(value = "出生日期")
        private LocalDate patBirthday;

        @ApiModelProperty(value = "证件类型")
        private String patIdentType;

        @ApiModelProperty(value = "证件号码")
        private String patIdentNo;

        @ApiModelProperty(value = "手机号")
        private String patMobile;

        @ApiModelProperty(value = "民族")
        private String patNation;

        @ApiModelProperty(value = "学历")
        private String patEducation;

        @ApiModelProperty(value = "婚姻状况")
        private String patMarriage;

        public TblPatient build() {
            TblPatient patient = new TblPatient();
            patient.setPatName(this.patName);
            patient.setPatSex(this.patSex);
            patient.setPatBirthday(this.patBirthday);
            patient.setPatIdentType(this.patIdentType);
            patient.setPatIdentNo(this.patIdentNo);
            patient.setPatMobile(this.patMobile);
            patient.setPatNation(this.patNation);
            patient.setPatEducation(this.patEducation);
            patient.setPatMarriage(this.patMarriage);
            return patient;
        }
    }

    public interface Patient {

    }

    public interface Phone {

    }
}
